package mypack.java;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class IntialServlet
 */
public class IntialServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    int i = 0;   
    /**
     * @see HttpServlet#HttpServlet()
     */
    public IntialServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println("This is Inttial servlet");
		ServletConfig cg = getServletConfig();
		cg.getInitParameter("param1");
		System.out.println("Init parameter"+ cg.getInitParameter("param1"));
		
		ServletContext context = getServletContext();
		context.getInitParameter("cotextParam1");
		System.out.println("Context Init parameter"+ context.getInitParameter("cotextParam1"));
		
		response.setContentType("text/html");//mime type
		PrintWriter pw = response.getWriter();
		pw.println("<h1>Welcome to"+cg.getInitParameter("param1")+" InitialServlet<h1>");
		pw.println("end of application"+i++);
		pw.close();
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
